<?php
session_start();
require "lib/db.php";
require "lib/case-function.php";
require "lib/status-function.php";
require "lib/priority-function.php";
require "lib/customer-function.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Case</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
			$("#case").css({"background-color":"#FFF",	
	"color":"#000"});
    });
</script>
<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:2px 3px;
		opacity:0.8;
		text-align:center;
	}

</style>
</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<!--content-->
<div id="content">
<table width="100%" border="1" cellspacing="0">
  <tr>
    <th colspan="10">List Cases</th>
  </tr>
  <tr>
    <th>CaseID</th>
    <th>Title</th>
    <th>Description</th>
    <th>Case Year</th>
    <th>Case Month</th>
    <th>Customer Name</th>
    <th>Status</th>
    <th>Priority</th>
    <th>Solution</th>
    <th><a href="add-case.php">Add Case</a></th>
  </tr>
	<?php
    $listcase = getAllCase();
	while($case = mysql_fetch_array($listcase)){
		$statusID = $case['StatusID'];
		$status = mysql_fetch_array(getStatusByID($statusID));
		$priorityID = $case['PriorityID'];
		$priority = mysql_fetch_array(getPriorityByID($priorityID));
		$customerID = $case['CustomerID'];
		$customer = mysql_fetch_array(getCustomerByID($customerID));
		ob_start();
    ?>
  <tr>
    <td>{CaseID}</td>
    <td>{Title}</td>
    <td>{Description}</td>
    <td>{CaseYear}</td>
    <td>{CaseMonth}</td>
    <td>{CustomerName}</td>
    <td>{Status}</td>
    <td>{Priority}</td>
    <td>{Solution}</td>
    <td><a href="edit-case.php?caseid={CaseID}">Edit</a> - <a onClick="return confirm('Are you sure delete this case?');" href="delete-case.php?caseid={CaseID}">Delete</a></td>
  </tr>
 	<?php 
	$s = ob_get_clean();
	$s = str_replace("{CaseID}","$case[CaseID]",$s);
	$s = str_replace("{Title}","$case[Title]",$s);
	$s = str_replace("{Description}","$case[Description]",$s);
	$s = str_replace("{CaseYear}","$case[CaseYear]",$s);
	$s = str_replace("{CaseMonth}","$case[CaseMonth]",$s);
	$s = str_replace("{CustomerName}","$customer[CustomerName]",$s);
	$s = str_replace("{Status}","$status[Status]",$s);
	$s = str_replace("{Priority}","$priority[Priority]",$s);
	$s = str_replace("{Solution}","$case[Solution]",$s);
	echo $s;
	}
	?>
</table>
</div>

<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>